package com.lineage.data.npc.other;

import com.lineage.data.executor.NpcExecutor;
import com.lineage.server.model.Instance.L1MonsterInstance;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Object;
import com.lineage.server.serverpackets.S_DoActionGFX;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.utils.CheckUtil;
import com.lineage.server.world.World;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Npc_Conquestn extends NpcExecutor {
  private static final Log _log = LogFactory.getLog(Npc_Conquestn.class);
  
  private boolean _checkDead;
  
  public static NpcExecutor get() {
    return new Npc_Conquestn();
  }
  
  public int type() {
    return 8;
  }
  
  public L1PcInstance death(L1Character lastAttacker, L1NpcInstance npc) {
    try {
      L1PcInstance pc = CheckUtil.checkAtkPc(lastAttacker);
      if (pc != null) {
        ArrayList<L1Character> targetList = npc.getHateList().toTargetArrayList();
        if (!targetList.isEmpty()) {
          Iterator<L1Character> iterator = targetList.iterator();
          L1PcInstance l1PcInstance = null;
          while (iterator.hasNext()) {
            L1Character cha = iterator.next();
            if (cha instanceof L1PcInstance)
               l1PcInstance = (L1PcInstance)cha; 
          } 
          Iterator<L1Character> iterator2 = targetList.iterator();
          while (iterator2.hasNext()) {
            L1Character cha = iterator2.next();
            if (cha instanceof L1PcInstance) {
              L1PcInstance find_pc = (L1PcInstance)cha;
              if (!this._checkDead || find_pc.getCurrentHp() <= 0)
                continue; 
              find_pc.isDead();
            } 
          } 
        } 
      } 
      ArrayList<L1Object> list = World.get().getVisibleObjects((L1Object)pc, -1);
      if (list == null)
        return pc; 
      Iterator<L1Object> iterator3 = list.iterator();
      while (iterator3.hasNext()) {
        L1Object object = iterator3.next();
        if (object instanceof L1MonsterInstance) {
          L1MonsterInstance dota = (L1MonsterInstance)object;
          dota.broadcastPacketAll((ServerBasePacket)new S_DoActionGFX(dota.getId(), 2));
          dota.receiveDamage((L1Character)pc, 300);
        } 
      } 
      pc.sendPacketsAll((ServerBasePacket)new S_SkillSound(pc.getId(), 7771));
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
    return null;
  }
}
